package communication.common.business.base;

import lombok.Builder;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

/**
 * 通用响应消息
 * @author mac
 */
@Data
@ToString
@Builder
public class ResponseDto<T> implements Serializable {

    /**
     * 业务类型
     */
    private String op;

    /**
     * 响应码 ：200 为success
     */
    private int code;

    /**
     * 错误信息
     */
    private String errMsg;

    /**
     * 附加数据
     */
    private T result;

    public static ResponseDto fail(int code, String msg) {
        return ResponseDto.builder()
                .code(code)
                .errMsg(msg)
                .build();
    }

    public static <T>  ResponseDto success(T t){
        return ResponseDto.builder()
                .code(200)
                .result(t)
                .build();
    }

    public static <T>  ResponseDto success(String op,T t){
        return ResponseDto.builder()
                .op(op)
                .code(200)
                .result(t)
                .build();
    }

}
